package com.example.lenovo.democ;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;

public class ScoreAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<StudentScore> scores;
    private IoDelStuScore listener;

    public ScoreAdapter(Context context,ArrayList<StudentScore> scores,IoDelStuScore listener){
        this.context=context;
        this.scores=scores;
        this.listener=listener;
    }
    @Override
    public int getCount() {
        return scores.size();
    }

    @Override
    public Object getItem(int i) {
        return scores.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.score_list, viewGroup, false);
            ScoreHolder ScoreHolder = new ScoreHolder();
            ScoreHolder.nameview = view.findViewById(R.id.nameview);
            ScoreHolder.androidview=view.findViewById(R.id.androidview);
            ScoreHolder.englishview=view.findViewById(R.id.englishview);
            ScoreHolder.delimg=view.findViewById(R.id.delimg);
            view.setTag(ScoreHolder);
        }

        final StudentScore studentScore=scores.get(i);
        ScoreHolder ScoreHolder= (ScoreHolder) view.getTag();
        ScoreHolder.nameview.setText("姓名"+" "+studentScore.getName());
        ScoreHolder.androidview.setText("安卓"+" "+String.valueOf(studentScore.getAndroid()));
        ScoreHolder.englishview.setText("英语"+" "+String.valueOf(studentScore.getEnglish()));

        ScoreHolder.delimg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.del(studentScore);
            }
        });
           return view;
    }
}
